package com.iss.apartmentmanage.service.impl;

import com.iss.apartmentmanage.mapper.ConsoleMapper;
import com.iss.apartmentmanage.model.MyResponseData;
import com.iss.apartmentmanage.service.ConsoleService;
import com.iss.apartmentmanage.utils.Create30DayMapUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ConsoleServiceImpl implements ConsoleService {
   @Autowired
   ConsoleMapper mapper;

    /**
     * 今日入住
     * @return
     */
   public Integer selectCheckinForDay(){
       int count=0;
       try {
           count = mapper.selectCheckinForDay();
           System.out.println(count);
       }catch (Exception e){
          // e.printStackTrace();
           System.out.println("今日入住查询0");

       }
      return count;
   }

    /**
     * 本月入住
     * @return
     */
    @Override
    public Integer selectCheckinForMonth() {
        int count=0;
        try {
            count = mapper.selectCheckinForMonth();
        }catch (Exception e){
           // e.printStackTrace();
            System.out.println("本月入住查询0");

        }

        return count;
    }

    /**
     * 今日销售额
     * @return
     */
    @Override
    public Integer selectMoneyForDay() {

        int count=0;
        try {
            count = mapper.selectMoneyForDay();
        }catch (Exception e){
           // e.printStackTrace();
            System.out.println("今日销售额查询0");
        }
        return count;
    }

    /**
     * 本月销售额
     * @return
     */
    @Override
    public Integer selectMoneyForMonth() {

        int count=0;
        try {
            count = mapper.selectMoneyForMonth();
        }catch (Exception e){
           // e.printStackTrace();
            System.out.println("今本月销售额查询0");

        }
        return count;
    }

    /**
     * 折线图count
     * @return
     */
    @Override
    public List<Map<String,String>> checkinChartCount() {
        List<Map<String, String>> chartCount = mapper.checkinChartCount();
        List<Map<String,String>> day30= Create30DayMapUtil.createMap(20);
        for(int i=0;i<day30.size();i++){
            Map<String,String> map30=day30.get(i);
            for (int j=0;j<chartCount.size();j++){
                Map<String,String> map=chartCount.get(j);
                if (StringUtils.equals(map30.get("time"),map.get("date"))){
                   map30.put("checkinData",String.valueOf(map.get("count"))) ;
                }
            }
        }

        return day30;
    }
    /**
     * 折线图money
     */

    @Override
    public List<Map<String, String>> checkinChartMoney() {
        List<Map<String, String>> chartMoney = mapper.checkinChartMoney();
        List<Map<String,String>> day30= Create30DayMapUtil.createMap(20);
        for(int i=0;i<day30.size();i++){
            Map<String,String> map30=day30.get(i);
            for (int j=0;j<chartMoney.size();j++){
                Map<String,String> map=chartMoney.get(j);
                if (StringUtils.equals(map30.get("time"),map.get("date"))){
                    map30.put("checkinData",String.valueOf(map.get("money"))) ;
                }
            }
        }
        return day30;
    }



















}
